package com.qdlc.p2p.biz.modelbuidler;

import com.qdlc.p2p.common.constant.Summary;
import com.qdlc.p2p.common.constant.TradeCode;
import com.qdlc.p2p.common.util.DateUtil;
import com.qdlc.p2p.common.util.OrderNoUtil;
import com.qdlc.p2p.dal.dto.BorrowTender;
import com.qdlc.p2p.dal.model.TppModel;
import com.qdlc.p2p.dal.model.TppTradeLogModel;


public class TppModelBuilder {

	TppModel tppModel;
	
	Summary summaryConstant;
	String tppUserCustId;
	String toTppUserCustId;
	double money;
	BorrowTender tender;
	TradeCode tradeCode;
	
	private TppModelBuilder() {
		tppModel = new TppModel();
	}
	
	public static TppModelBuilder newBuilder(){
		return new TppModelBuilder();
	}

	public TppModelBuilder setSummaryConstant(Summary summaryConstant) {
		this.summaryConstant = summaryConstant;
		return this;
	}


	public TppModelBuilder setTppUserCustId(String tppUserCustId) {
		this.tppUserCustId = tppUserCustId;
		return this;
	}

	public TppModelBuilder setToTppUserCustId(String toTppUserCustId) {
		this.toTppUserCustId = toTppUserCustId;
		return this;
	}

	public TppModelBuilder setMoney(double money) {
		this.money = money;
		return this;
	}

	public TppModelBuilder setTender(BorrowTender tender) {
		this.tender = tender;
		return this;
	}

	public TppModelBuilder setTradeCode(TradeCode tradeCode) {
		this.tradeCode = tradeCode;
		return this;
	}
	
	public TppModel build(){
		tppModel.setTppUserCustId(tppUserCustId);
		tppModel.setToTppUserCustId(toTppUserCustId);
		tppModel.setMoney(money);
		tppModel.setTender(tender);
		tppModel.setOrderId(OrderNoUtil.getInstance().getSerialNumber());
		tppModel.setOut_trade_code(tradeCode.toString());
		tppModel.setOrderDate(DateUtil.dateStr7(DateUtil.getNow()));
		tppModel.setAddTime(DateUtil.getNow());
		if(summaryConstant != null){
			//平台服务类型
			tppModel.setServiceType(TppTradeLogModel.getTppServiceType(summaryConstant.getSummaryType()));
			tppModel.setSummary(summaryConstant.getSummaryName());
			//第三方平台服务类型
			tppModel.setTppType(summaryConstant.getSummaryType());
		}
		return tppModel;
	}
}
